-
Notifications
You must be signed in to change notification settings - Fork 2
feat(strings): longest self contained substring #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Warning Rate limit exceeded@BrianLusina has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 28 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughThis PR introduces a new "Longest Self-Contained Substring" algorithm to the pystrings collection. Changes include a comprehensive README explaining the problem and solution, two implementation functions using character occurrence mapping, a full test suite, and updates to the project directory index. Changes
Sequence DiagramsequenceDiagram
participant Caller
participant longest_self_contained_substring
participant Helper as Character Mapping
Caller->>longest_self_contained_substring: Call with string s
longest_self_contained_substring->>Helper: Precompute first & last<br/>occurrences of each char
Helper-->>longest_self_contained_substring: Map of char positions
rect rgba(100, 200, 150, 0.3)
note over longest_self_contained_substring: Iterate all substrings<br/>(excluding full string)
longest_self_contained_substring->>longest_self_contained_substring: For each substring,<br/>verify no char appears<br/>outside its bounds
end
alt Valid self-contained found
longest_self_contained_substring-->>Caller: Return max length
else No valid substring
longest_self_contained_substring-->>Caller: Return -1
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Areas requiring attention:
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (1)
pystrings/longest_self_contained_substring/test_longest_self_contained_substring.py (1)
5-71: Consider more descriptive test method names.While the test coverage is comprehensive and both functions are properly validated, test method names like
test_1,test_2, etc. don't convey what scenario is being tested. Consider using descriptive names liketest_returns_two_for_xyyxortest_returns_negative_one_when_no_valid_substringto improve test readability and maintainability.Example refactor for a few tests:
- def test_1(self): + def test_returns_two_for_string_with_mirrored_chars(self): s = "xyyx" expected = 2 actual = longest_self_contained_substring(s) self.assertEqual(expected, actual) - def test_2(self): + def test_returns_negative_one_when_no_self_contained_substring(self): s = "xyxy" expected = -1 actual = longest_self_contained_substring(s) self.assertEqual(expected, actual)Also applies to: 73-139
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (36)
pystrings/longest_self_contained_substring/images/longest_self_contained_substring_example_1.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/longest_self_contained_substring_example_2.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/longest_self_contained_substring_example_3.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/longest_self_contained_substring_example_4.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/longest_self_contained_substring_example_5.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/longest_self_contained_substring_example_6.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/longest_self_contained_substring_example_7.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/longest_self_contained_substring_example_8.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_1.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_10.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_11.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_12.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_13.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_14.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_15.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_16.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_17.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_18.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_19.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_2.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_20.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_21.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_22.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_23.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_24.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_25.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_26.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_27.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_28.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_3.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_4.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_5.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_6.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_7.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_8.pngis excluded by!**/*.pngpystrings/longest_self_contained_substring/images/solution/longest_self_contained_substring_solution_9.pngis excluded by!**/*.png
📒 Files selected for processing (5)
DIRECTORY.md(1 hunks)pystrings/length_of_longest_substring/README.md(1 hunks)pystrings/longest_self_contained_substring/README.md(1 hunks)pystrings/longest_self_contained_substring/__init__.py(1 hunks)pystrings/longest_self_contained_substring/test_longest_self_contained_substring.py(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
pystrings/longest_self_contained_substring/test_longest_self_contained_substring.py (1)
pystrings/longest_self_contained_substring/__init__.py (2)
longest_self_contained_substring(1-52)max_substring_length(55-97)
🪛 LanguageTool
pystrings/longest_self_contained_substring/README.md
[style] ~8-~8: This phrase is redundant. Consider using “outside”.
Context: ...n t does not appear anywhere else in s (outside of t). In other words, all characters in ...
(OUTSIDE_OF)
[style] ~10-~10: Consider using a different adverb to strengthen your wording.
Context: ...In other words, all characters in t are completely unique to that substring within the str...
(COMPLETELY_ENTIRELY)
[style] ~77-~77: Using many exclamation marks might seem excessive (in this case: 32 exclamation marks for a text that’s 6188 characters long)
Context: ...elf_contained_substring_solution_1.png)

🪛 markdownlint-cli2 (0.18.1)
DIRECTORY.md
706-706: Unordered list indentation
Expected: 0; Actual: 2
(MD007, ul-indent)
707-707: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
🔇 Additional comments (3)
pystrings/length_of_longest_substring/README.md (1)
1-1: LGTM - Nice formatting improvement!Converting the plain text title to a proper Markdown header improves document structure and readability.
pystrings/longest_self_contained_substring/README.md (1)
1-112: Excellent documentation!The README provides comprehensive coverage of the problem definition, solution approach with detailed algorithm steps, and complexity analysis. The use of images for examples and solution walkthrough enhances understanding.
pystrings/longest_self_contained_substring/__init__.py (1)
1-97: Clarify the purpose of having two implementations.This module exports two functions that solve the same problem but with vastly different time complexities:
longest_self_contained_substring: O(n³) brute-force approachmax_substring_length: O(n) optimized approach (matches the algorithm described in the README)Questions to consider:
- Is the brute-force implementation needed? If it's for educational purposes or as a reference implementation, this should be documented in the module docstring or function docstrings.
- Which function should users prefer? The README only describes the O(n) algorithm, suggesting
max_substring_lengthis the intended solution.- Should both be public? Consider whether one should be private (prefixed with
_) or if one should be removed entirely.Would you like me to help generate a module-level docstring that clarifies when to use each function, or should one implementation be removed?
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Describe your change:
Find the longest self contained substring
Checklist:
Fixes: #{$ISSUE_NO}.Summary by CodeRabbit
New Features
Documentation
Tests